package com.greensam.pixelengine.controller;

import com.greensam.pixelengine.annotation.AuthCheck;
import com.greensam.pixelengine.facade.FileFacadeService;
import com.greensam.pixelengine.pojo.base.BaseResponse;
import com.greensam.pixelengine.pojo.emuns.RoleEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 基础功能
 *
 * @author Macro_Ray
 * @since 2025/6/13 16:38
 */
@Tag(name = "BaseController", description = "基础模块")
@RestController
@RequestMapping("/")
@RequiredArgsConstructor
public class BaseController {

    private final FileFacadeService fileFacadeService;

    @Operation(summary = "健康检查")
    @GetMapping("/health")
    public BaseResponse<String> health() {
        return BaseResponse.success("OK");
    }

    @Operation(summary = "测试文件上传")
    @PostMapping("/file/test/upload")
    @AuthCheck(mustRole = {RoleEnum.ADMIN})
    public BaseResponse<String> testUploadFile(@RequestPart MultipartFile multipartFile) {
        return BaseResponse.success(fileFacadeService.testUploadFile(multipartFile));
    }

    @Operation(summary = "测试文件下载")
    @PostMapping("/file/test/download")
    @AuthCheck(mustRole = {RoleEnum.ADMIN})
    public BaseResponse<Void> testDownloadFile(HttpServletResponse response, String filePath) {
        return BaseResponse.success(fileFacadeService.testDownloadFile(response, filePath));
    }

}
